package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    //插入订单数据
    public void submit(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id} ")
    Orders findByOrderId(Long id);

    /**
     * 分页查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageFind(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 取消订单
     * @param id
     */
    @Update("update orders set status = 6,cancel_time = now() where id = #{id}")
    void cancel(Long id);

    /**
     * 管理端分页查询订单
     * @param pageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO pageQueryDTO);

    //各订单状态数量统计
    @Select("select count(id) from orders where status = #{status}")
    Integer statistic(Integer status);

    //根据订单状态和订单时间查询订单信息
    @Select("select * from orders where status = #{deliveryInProgress} and order_time < #{time} ")
    List<Orders> findByStatusAndOrdertime(Integer deliveryInProgress, LocalDateTime time);

    //查询订单管理数据(工作台)
    Integer countByMap(Map map);
}
